package com.twu.biblioteca;

/**
 * Created by Janu on 09/06/14.
 * Class: Customer.java
 * Methods: public boolean listOfBooks(Book[] booksList)
 *          public String customerReturnOrCheckOutBook(Book[] bookList,String option, String bCode)
 *
 */


import java.util.Iterator;



public class Customer extends Option{

    //Parameters
    private String custNumber;
    private String custPassword;
    private String custName;
    private String custEmail;
    private String custPhone;

    //Constructors
    Customer(){
        this.custNumber = "";
        this.custPassword = "";
        this.custName = "";
        this.custEmail = "";
        this.custPhone = "";
    }

    public Customer(String custNumber, String custPassword, String custName, String custEmail, String custPhone) {
        this.custNumber = custNumber;
        this.custPassword = custPassword;
        this.custName = custName;
        this.custEmail = custEmail;
        this.custPhone = custPhone;
    }

    public Customer(OptionManager optionManager){
        this.optionManager = optionManager;
    }


    //Customer login
    public String login(String custNumber, String custPassword) {


        Customer cust;
        DataSet ds = new DataSet();

        Iterator iter = ds.getCustomersDataSet().iterator();
        String stmt="";

        while(iter.hasNext()){
            cust = (Customer) iter.next();
            if(cust.getCustNumber().equals(custNumber) && cust.getCustPassword().equals(custPassword)){
                stmt = "Successful login";
                this.custName = cust.getCustName();
                this.custNumber = cust.getCustNumber();
                this.custEmail = cust.getCustEmail();
                this.custPhone = cust.getCustPhone();
                this.custPassword = cust.getCustPassword();
                break;
            }
            else if(cust.getCustNumber().equals(custNumber) && !cust.getCustPassword().equals(custPassword)){
                stmt =  "Invalid password";
            }
            else{
                stmt = "Invalid user";
            }
        }
        return stmt;
    }

    //Getters
    public String getCustName() {
        return this.custName;
    }

    public String getCustNumber(){
        return this.custNumber;
    }

    public String getCustPassword(){
        return this.custPassword;
    }

    public String getCustEmail(){
        return this.custEmail;
    }

    public String getCustPhone(){
        return this.custPhone;
    }

    String doSomething(Customer customer) {
        return optionManager.getCustomerInformation(customer);
    }
}
